package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_MZJYJLJYXMMX;

public class GetEMR_MZJYJLJYXMMXData {
	
	private static final Log log = LogFactory.getLog(GetEMR_MZJYJLJYXMMXData.class);
	public static List<EMR_MZJYJLJYXMMX> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_MZJYJLJYXMMX> re = new ArrayList<EMR_MZJYJLJYXMMX>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        
	        String sql = "select "
	        		+"'' as HZZSYH,"
					+"b.yljgdm as YLJGZZJGDM,"
					+"a.jzlsh as MJZH,"
					+"b.jyzblsh as JXXMLSH,"
					+"'' as JXXMMXLSH,"
					+"a.dzsqdbh as DZSQDBH,"
					+"b.jcff as JYFFMC,"
					+"b.jczbmc as JYXMMC,"
					+"b.jczbmc as JYLB,"
					+"b.jczbdm as JYXMDM,"
					+"b.jczbjg as JYJGDM,"
					+"b.jydljg as JYDLJGDCLZ,"
					+"b.jydljgjsdw as JYDLJGJLDW,"
					+"to_char(a.jyrq,'YYYY-MM-dd HH24:mi:ss') as JYRQ,"
					+"a.bbdm as BBLB,"
					+"a.bbmc as JYBBH,"
					+"'' as BBZT,"
					+"'1990-01-01 00:00:00' as BBCYRQSJ,"
					+"'1990-01-01 00:00:00' as JSBBSJ,"
					+"a.jyjsbh as JYJSGH,"
					+"a.jyjsqm as JYJSQM,"
					+"a.jyysbh as JYYSGH,"
					+"a.jyysqm as JYYSQM,"
					+"'' as JYCKZ,"


					+"a.bgrgh as BGYSGH,"
					+"a.bgrxm as BGYSQM,"
					+"a.shrgh as SHYSGH,"
					+"a.shrxm  as SHYSQM,"
					+"'' as JYXMMC,"
					+"'' as ZRLSH,"	
					+"to_char(a.ywscsj,'YYYY-MM-dd HH24:mi:ss') as BCRQ,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+" from TB_LIS_JYBG a  left join   TB_LIS_JYJGZB b" 
					+" on a.yljgdm = b.yljgdm and a.bgdh = b.bgdh  ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
//	            System.out.println(result.getInt("YYDAH"));
	        	EMR_MZJYJLJYXMMX temp = new EMR_MZJYJLJYXMMX();
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setYLJGZZJGDM(result.getString("YLJGZZJGDM"));
	        	temp.setMJZH(result.getString("MJZH"));
	        	temp.setJXXMLSH(result.getString("JXXMLSH"));
	        	temp.setJXXMMXLSH(result.getString("JXXMMXLSH"));
	        	temp.setDZSQDBH(result.getString("DZSQDBH"));

	        	temp.setJYFFMC(result.getString("JYFFMC"));
	        	temp.setJYXMMC(result.getString("JYXMMC"));
	        	temp.setJYLB(result.getString("JYLB"));
	        	temp.setJYXMDM(result.getString("JYXMDM"));
	        	temp.setJYJGDM(result.getString("JYJGDM"));
	        	temp.setJYDLJGDCLZ(result.getString("JYDLJGDCLZ"));
	        	temp.setJYDLJGJLDW(result.getString("JYDLJGJLDW"));
	        	temp.setJYRQ(result.getString("JYRQ"));
	        	temp.setBBLB(result.getString("BBLB"));
	        	temp.setJYBBH(result.getString("JYBBH"));
	        	temp.setBBZT(result.getString("BBZT"));
	        	temp.setBBCYRQSJ(result.getString("BBCYRQSJ"));
	        	temp.setJSBBSJ(result.getString("JSBBSJ"));
	        	temp.setJYJSGH(result.getString("JYJSGH"));
	        	temp.setJYJSQM(result.getString("JYJSQM"));
	        	temp.setJYYSGH(result.getString("JYYSGH"));
	        	temp.setJYYSQM(result.getString("JYYSQM"));
	        	temp.setJYCKZ(result.getString("JYCKZ"));

	        	temp.setZRLSH(result.getString("ZRLSH"));
	        	temp.setBCRQ(result.getString("BCRQ"));
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
